<?php
namespace app\manage\controller;

class AuditCpsInfo extends Base
{
    public function index(){
        if(request()->isAjax() || input('?export')){
            $page = input('page');
            $limit = input('limit');
            $channelId = input('channel_id');

            $where['channel_id'] = 1000;
            !empty($channelId) && $where['cps_id'] = $channelId;

            if( ! $count=model('Channel')->where($where)->count() ){
                $this->layTable();
            }

            $select = model('Channel')
                ->where($where)
                ->limit(($page-1)*$limit, $limit)
                ->order('cps_id desc')
                ->select();

            $data = [];
            $channelType = config('channel_type');
            foreach ($select as $k=>$v){
                $data[] = [
                    'cps_id' => $v['cps_id'],
                    'cps_name' => $v['cps_name'],
                    'cps_type' => $channelType[ $v['cps_type'] ],
                    'pay_rate' => $v['pay_rate'],
                    'channel_rate' => $v['channel_rate'],
                    'tax_rate' => $v['tax_rate'],
                    'audit_time' => $v['audit_time'] ? date('Y-m-d H:i:s', $v['audit_time']) : '',
                    'contact_man' => $v['contact_man'], //开户人
                    'open_account' => $v['open_account'], //开户账号
                    'open_name' => $v['open_name'], //所属银行
                    'open_bank' => $v['open_bank'], //开户银行
                    'cps_week' => $v['cps_week'],
                ];
            }
            $this->layTable(0, 'CPS转账列表', $data, $count);
        }else{
            $channelData = model('ViewChannel')->field('cps_id,cps_name')->where('channel_id', 1000)->order('cps_id desc')->select();
            return view('', ['channel_data'=>$channelData]);
        }
    }

    //编辑
    public function edit(){
        model('Channel')->save(input(), ['cps_id'=>input('cps_id')]) ? $this->layJson(0, '编辑成功') : $this->layJson(1, '编辑失败，请重试');
    }
}